#include "wifi_proc.h"
#include "wifi_ap.h"
#include "wifi_sta.h"
#include "dns_server.h"
#include "web_server.h"
#include <esp_log.h>
#include "pin_map.h"
#include "driver/gpio.h"

#define TAG "wifi"

esp_err_t wifi_proc_init(void)
{
    char wifi_name[64] = {0};
    char wifi_pwd[64] = {0};

    if (nvs_read_wifi_data((char *)"WIFI Config Is OK!", wifi_name, wifi_pwd) == ESP_OK) {
        ESP_LOGI(TAG, "WIFI SSID  %s", wifi_name);
        ESP_LOGI(TAG, "WIFI PWD   %s", wifi_pwd);

        ESP_LOGI(TAG, "start init wifi station mode");
        wifi_init_sta(wifi_name, wifi_pwd);
    } else {
        ESP_LOGI(TAG, "not found wifi config info");
        ESP_LOGI(TAG, "start init wifi softap mode");

        wifi_init_ap();
        dns_server_start();
        web_server_start();
    }   
    return ESP_OK;
}

